package com.jiesen.base.modules.certificate.textbook.controller;

import com.jiesen.base.modules.certificate.textbook.model.JsTextbookBinding;
import com.jiesen.base.modules.certificate.textbook.service.JsTextbookBindingService;
import com.jiesen.base.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 套餐信息
 */
@RestController
@RequestMapping("/textbook/binding")
public class JsTextbookBindingController {

    @Autowired
    private JsTextbookBindingService jsTextbookBindingService;

    //增加一个活动信息
    @PostMapping("/create")
    public R create(@RequestBody JsTextbookBinding jsTextbookBinding){
        boolean b = jsTextbookBindingService.save(jsTextbookBinding);
        if(!b){
            return R.error();
        }
        return R.ok();
    }

    //删除一个套餐信息
    @GetMapping("delete")
    public R delete(@RequestParam("id")Integer id){
        boolean b = jsTextbookBindingService.removeById(id);
        if(!b){
            return R.error();
        }
        return R.ok();
    }

    //修改一个套餐信息
    @PostMapping("/edit")
    public R edit(@RequestBody JsTextbookBinding jsTextbookBinding){
        boolean b = jsTextbookBindingService.updateById(jsTextbookBinding);
        if(!b){
            return R.error();
        }
        return R.ok();
    }

    //查看单个
    @GetMapping("/view")
    public R viewOne(@RequestParam("id")Integer id){
        JsTextbookBinding jsTextbookBinding = jsTextbookBindingService.getById(id);
        return R.ok().put("data",jsTextbookBinding);
    }

    //根据条件查询
    @PostMapping("/view")
    public R view(@RequestBody JsTextbookBinding jsTextbookBinding){
        return jsTextbookBindingService.page(jsTextbookBinding);
    }

}
